package net.maku.generator.controller;

import lombok.AllArgsConstructor;
import net.maku.generator.common.page.PageResult;
import net.maku.generator.query.GenCodeIssueQuery;
import net.maku.generator.common.utils.Result;
import net.maku.generator.entity.GenCodeIssueEntity;
import net.maku.generator.service.GenCodeIssueService;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
* 代码问题管理
*
* @author 代码小子 crudboy@163.com
* @since 1.0.0 2024-11-22
*/
@RestController
@RequestMapping("gen/gen_code_issue")
@AllArgsConstructor
public class GenCodeIssueController {
    private final GenCodeIssueService genCodeIssueService;

    @GetMapping("page")
    public Result<PageResult<GenCodeIssueEntity>> page(GenCodeIssueQuery query){
        PageResult<GenCodeIssueEntity> page = genCodeIssueService.page(query);

        return Result.ok(page);
    }

    @GetMapping("list")
    public Result<List<GenCodeIssueEntity>> list(){
        List<GenCodeIssueEntity> list = genCodeIssueService.getList();

        return Result.ok(list);
    }

    @GetMapping("{id}")
    public Result<GenCodeIssueEntity> get(@PathVariable("id") Long id){
        GenCodeIssueEntity entity = genCodeIssueService.getById(id);

        return Result.ok(entity);
    }

    @PostMapping
    public Result<String> save(@RequestBody GenCodeIssueEntity entity){
        genCodeIssueService.save(entity);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody GenCodeIssueEntity entity){
        genCodeIssueService.updateById(entity);

        return Result.ok();
    }

    @DeleteMapping
    public Result<String> delete(@RequestBody Long[] ids){
        genCodeIssueService.removeBatchByIds(Arrays.asList(ids));

        return Result.ok();
    }
}